﻿using UnityEditor;
using UnityEngine;
using System.Collections;

public class OldAssetBundleRecord 
{
    [MenuItem("AssetBundle/CopyNewAssetBundleBecomeRecord_Android   存档", false, 601)]
    public static void CopyNewAssetBundleBecomeRecord_Android()
    {
        CopyNewAssetBundleBecomeRecord(Platform.GetPlatformFolder(RuntimePlatform.Android));
    }

    [MenuItem("AssetBundle/CopyNewAssetBundleBecomeRecord_IOS   存档", false, 601)]
    public static void CopyNewAssetBundleBecomeRecord_IOS()
    {
        CopyNewAssetBundleBecomeRecord(Platform.GetPlatformFolder(RuntimePlatform.IPhonePlayer));
    }

    [MenuItem("AssetBundle/CopyNewAssetBundleBecomeRecord_Windows   存档", false, 601)]
    public static void CopyNewAssetBundleBecomeRecord_Windows()
    {
        CopyNewAssetBundleBecomeRecord(Platform.GetPlatformFolder(RuntimePlatform.WindowsEditor));
    }

    public static void CopyNewAssetBundleBecomeRecord(string target_folder)
    {
        var new_version = VersionTool.GetLastestVersion();
        var to_dir_path = FileTool.PathCombine(AssetBundleConfig.OldAssetBundleDirPath, target_folder);
        to_dir_path = FileTool.PathCombine(to_dir_path, new_version);

        var sources_dir_path = FileTool.PathCombine(AssetBundleConfig.AssetBundlesOutputPath, target_folder);
        
        if(!System.IO.Directory.Exists(sources_dir_path))
        {
            return;
        }

        FileTool.ForeachFiles(sources_dir_path, FileTool.ForeachEnum.File, (string full_file_path) =>
        {
            full_file_path = FileTool.ReplacePathSign(full_file_path);
            var to_file_path = FileTool.PathCombine(to_dir_path, full_file_path.Replace(sources_dir_path, ""));

            // 创建路径
            var _to_dit_path = System.IO.Path.GetDirectoryName(to_file_path);
            if(!System.IO.Directory.Exists(_to_dit_path))
            {
                System.IO.Directory.CreateDirectory(_to_dit_path);
            }

            FileUtil.CopyFileOrDirectory(full_file_path, to_file_path);
        });
    }   

   
}
